<?php
/*
 *
 * @authors : IT123编程社区-mastudy
 * @email  :admin@it123.org
 * @bbs http://www.it123.org
 *  @link http://www.it123.org
 *  @Powered By  ©2016 www.it123.org[IT123编程社区]
 */
// 本类由系统自动生成，仅供测试用途
class ArticleAction extends PublicAction {



    public function index() {




        $this->display();
    }


    public function lists() {




        $articleDB = M('article');


        $where['article_verifystatus'] = 1;
        
        
        
        $where['article_ispubish'] = 1;
        
        
         $where['article_title'] = array('not in', '');
        
        
        

        import('ORG.Util.Page'); // 导入分页类
        $count = $articleDB->where($where)->count(); // 查询满足要求的总记录数
        $Page = new Page($count, 10); // 实例化分页类 传入总记录数和每页显示的记录数
        $show = $Page->show(); // 分页显示输出




        $order = 'article_time desc';



        $list = $articleDB->where($where)->order($order)->limit($offset, $pagesize)->select();

        $list = ToolsAction::resetArticleList($list);




        $this->assign('list', $list);


        $this->assign('page', $show);



        cookie('LURL', __SELF__);


        $this->display();
    }





    public function show() {


        $article_aid = $this->_get('id');


        if (!is_numeric($article_aid)) {


            $this->error('参数错误！');
        }





        $aDB = M('article');

        $where['article_id'] = $article_aid;
        $where['article_ispubish'] = 1;
        $where['article_verifystatus'] = 1;

        $data = $aDB->where($where)->find();

        if (!$data) {
            $this->error('数据不存在');
        }


        //更新文章的点赞数量//

        ToolsAction::updateArticleLikes($article_aid);


        //审查权限
        //免费获赠付费




        $aDB->where($where)->setInc('article_visits', 1);
        //作者信息

        $data['article_auther'] = ToolsAction::getUserinfo($data['article_uid'], 'member_nickname');

        $data['article_auther_face50'] = ToolsAction::getUserFace($data['article_author_id'], '50');



        $data['article_collections'] = ToolsAction::getItemCollectionCount($data['article_id'], 1);


        //文章信息   



        $data['article_title'] = htmlspecialchars_decode($data['article_title']);
        $data['article_desc'] = htmlspecialchars_decode($data['article_desc']);

        $data['article_text'] = htmlspecialchars_decode($data['article_text']);






        $data['article_time'] = date('Y-m-d', $data['article_addtime']);

        $tags = ToolsAction::gettags($data['article_id'], 1);












        $this->assign('article', $data);


        $this->assign('likeNO', $this->getlikeNumber(1, $data['article_id']));



        $this->assign('tags_list', $tags);



        $temp_arr = array(); //设一个全局的数组变量来保存引用评论的信息




        $commentDB = M('comment');

        $where['comment_item_id'] = $article_aid;

        $where['comment_module_id'] = 1;

        $where['comment_pid'] = 0;




        $commentList = $commentDB->where($where)->order('comment_time desc')->select();






        $this->assign('comment_count', count($commentList));

        $commentList = ToolsAction::ressetComment($commentList);

      

        $this->assign('commentList', $commentList);


        //文章的预读用户列表从喜欢字段里提取




        $listlike = ToolsAction::getModuleLikesLists(1, $article_aid);

        $this->assign('listlike', $listlike);


    //    $this->assign('AuthorList', $this->getMemberList(10, 'member_articles desc'));



        cookie('LURL', __SELF__);



        $this->display();
    }

    public function getParents($list, $comment_id) {
        $tree = array();
        foreach ($list as $item) {
            if ($item['comment_id'] == $comment_id) {
                if ($item['comment_pid'] > 0)
                    $tree = array_merge($tree, self::getParents($list, $item['comment_pid']));




                $tree[] = $item;
                break;
            }
        }
        return $tree;
    }

    public function docomment() {




        if (session('member.member_id')) {

            $uid = session('member.member_id');
        } else {


            $this->error('请登录！');

            die();
        }



        $comment_text = $this->_post('comment_text');
        $module_id = $this->_post('module_id');


        $item_id = $this->_post('item_id');



        $data['comment_item_id'] = $item_id;
        $data['comment_pid'] = 1;
        $data['comment_module_id'] = $module_id;
        $data['comment_uid'] = $uid;
        $data['comment_text'] = $comment_text;
        $data['comment_time'] = time();

        $commentDB = M('comment');
        if ($commentDB->add($data)) {


            $this->success('ok');
        } else {

            $this->error('sorry!');
        }
    }

    public function createHtml($path) {




        $statis_file = APP_PATH . '/html/Article/' . md5($id) . '.html';

        if (!file_exists($statis_file)) {

            $this->assign('title', $data['title']);


            $this->assign('content', $data['content']);


            $this->buildHtml('/Article/' . md5($id), '', 'show');
        }

        //echo file_get_contents($statis_file);//输出静态文件内容
    }

}

?>